package cn.itsource.pethome.annotation;

import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

//必须加
@WebListener
public class PermissionScanInitListener implements ServletContextListener {

    @Autowired
    private IPermissionScanService permissionScanService;
    /**
     * 初始化执行
     * @param servletContextEvent
     */
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        //会出现一个问题  插入数据很慢 解决方案实现一个线程去单独执行
        new Thread(new Runnable() {
            @Override
            public void run() {
                //去扫描注解
                permissionScanService.scanPermission();
//                System.out.println("被执行了");
            }
        }).start();//必须开启线程
    }

    /**
     * 销毁
     * @param servletContextEvent
     */
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        //不写任何代码
    }

}
